package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.AdminLogService;
import com.cskaoyan.market.db.common.BasePageInfo;
import com.cskaoyan.market.db.common.CommonData;
import com.cskaoyan.market.db.domain.MarketLog;
import com.cskaoyan.market.db.domain.MarketLogExample;
import com.cskaoyan.market.db.mapper.MarketLogMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author 小焦
 * @since 2023/03/20 13:41
 */
public class AdminLogServiceImpl implements AdminLogService {
    @Override
    public CommonData<MarketLog> list(BasePageInfo pageInfo, String name) {
        SqlSession sqlSession = MyBatisUtil.getSession();
        MarketLogMapper logMapper = sqlSession.getMapper(MarketLogMapper.class);
        // 开启PageHelper插件
		PageHelper.startPage(pageInfo.getPage(),pageInfo.getLimit());

        MarketLogExample logExample = new MarketLogExample();
        if (!StringUtils.isEmpty(name)) {
            logExample.createCriteria().andAdminLike(name);
        }
        logExample.setOrderByClause(pageInfo.getSort()+" " + pageInfo.getOrder());

        List<MarketLog> marketLogList = logMapper.selectByExample(logExample);

		PageInfo<MarketLog> logPageInfo = new PageInfo<>(marketLogList);
		CommonData<MarketLog> data = CommonData.data(logPageInfo);
		return data;
    }
}
